package com.cskaoyan.market.service.admin;/*
 *文件名: GeneralProblemServiceImple
 *创建者:wxin
 *创建时间:2024/5/6 15:14
 */

import com.cskaoyan.market.db.domain.MarketIssue;
import com.cskaoyan.market.db.domain.MarketIssueExample;
import com.cskaoyan.market.db.mapper.MarketIssueMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class AdminIssueServiceImpl implements AdminIssueService {
    @Autowired
    MarketIssueMapper marketIssueMapper;
    @Override
    public List<MarketIssue> list(Integer limit, Integer page, String question, String sort, String order) {

        MarketIssueExample marketIssueExample = new MarketIssueExample();
        marketIssueExample.setOrderByClause(sort + " " + order);
        MarketIssueExample.Criteria criteria = marketIssueExample.createCriteria();
        if (!StringUtils.isEmpty(question)) {
            criteria.andQuestionLike("%" + question + "%");
        }
        criteria.andDeletedEqualTo(false);
        PageHelper.startPage(page, limit);
        List<MarketIssue> marketIssues = marketIssueMapper.selectByExample(marketIssueExample);
        return marketIssues;
    }

    @Override
    public MarketIssue addIssue(MarketIssue marketIssue) {
        marketIssue.setAddTime(LocalDateTime.now());
        marketIssue.setUpdateTime(LocalDateTime.now());
        marketIssue.setDeleted(false);
        marketIssueMapper.insert(marketIssue);
        return marketIssue;
    }

    @Override
    public MarketIssue updateIssue(MarketIssue marketIssue) {
        marketIssue.setUpdateTime(LocalDateTime.now());
        marketIssueMapper.updateByPrimaryKeySelective(marketIssue);
        return marketIssue;
    }
    @Override
    public int logicalDelete(Integer id) {
        int updateCount = marketIssueMapper.logicalDeleteByPrimaryKey(id);
        return updateCount;
    }

}
